package com.gyg.controller;


import com.gyg.client.CloudRecordClient;
import com.gyg.domain.CloudUser;
import com.gyg.enums.SessionEnum;
import com.gyg.returns.RespEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * <p>
 * 文件上传下载记录表 前端控制器
 * </p>
 *
 * @author gyg
 * @since 2021-04-14
 */
@RestController
@RequestMapping("/cloud-record")
@Api(value = "文件操作记录", tags = "文件操作记录")
@Slf4j
public class CloudRecordController {

    @Resource
    private CloudRecordClient cloudRecordClient;

    @GetMapping("/recent")
    @ApiOperation(value = "实时操作记录")
    public RespEntity cloudRecordRecent(HttpSession session) {
        CloudUser cloudUser = (CloudUser) session.getAttribute(SessionEnum.USER.getCode());
        RespEntity respEntity = cloudRecordClient.getRecentCloudRecord(cloudUser.getId());
        return respEntity;
    }

    @GetMapping("/seven")
    @ApiOperation(value = "最近七日操作数量统计")
    public RespEntity recentRecordSevenDays(HttpSession session) {
        CloudUser cloudUser = (CloudUser) session.getAttribute(SessionEnum.USER.getCode());
        RespEntity respEntity = cloudRecordClient.getRecentSevenDays(cloudUser.getId());
        return respEntity;
    }

    @ApiOperation(value = "操作记录列表")
    @GetMapping("/list")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "pageNum", value = "当前页数", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "pageSize", value = "每页数量", required = true)
    })
    public RespEntity cloudRecordList(@RequestParam(value = "pageNum", required = true) Integer pageNum,
                                      @RequestParam(value = "pageSize", required = true) Integer pageSize,
                                      HttpSession session) {
        CloudUser cloudUser = (CloudUser) session.getAttribute(SessionEnum.USER.getCode());
        RespEntity respEntity = cloudRecordClient.cloudRecordList(cloudUser.getId(), pageNum, pageSize);
        return respEntity;
    }

}
